<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 用户筛选器ajax类
 * @package  	ajax
 * @subpackage  backend
 * @author   	create by allen.qiang
 */
require 'module/base/promotion/promotionHandler.class.php';
class ajax_userSelector {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1: //查询用户筛选器
                    $this->searchSelector();
                break;
			    case 2: //保存筛选器信息
                    $this->saveSelector();
                break;
				case 3: //删除用户筛选器
					$this->deleteSelector();
				break;
				case 4: //查询用户信息
					$this->getUserInfo();
				break;
            }

        }

    }
    
    /**
     * 查询用户筛选器列表
     */
    private function searchSelector() {

        global $G_PGLOB;
        
        //查询条件
		$promotionHandler = new promotionHandler( $G_PGLOB->DBCA ) ;
		$result_data	  = $promotionHandler->userSelectorList( $_REQUEST ) ;
		
		//查询结果
		$result_array = array(
            'page'  => $_REQUEST['page'] ,
            'total' => $_REQUEST['count'] ,
            'rows'  => array()
        );
        
		if ($result_data) {
            foreach($result_data as &$p_g) {
				$openFlg = $p_g->selectID; 	
                $result_array['rows'][] = array(
					'id' 	=> $p_g->selectID,
					'cell' 	=> array(
						'<a href="javascript: void(0);" onclick="selector.edit(' . $p_g->selectID . ')">修改</a>&nbsp;
						 <a href="javascript: void(0);" onclick="selector.view(' . $p_g->selectID . ')">查看</a>' ,
						$openFlg . '&nbsp;' ,
						$p_g->selectDisplayName,
						$p_g->description
					),
                );
            }
        }

        echo json_encode( $result_array );
    }
    
    /**
     * 保存用户筛选器信息
     *
     */
    private function saveSelector () {
    	global $G_PGLOB;
    	
    	$_REQUEST['creator'] = $G_PGLOB->currentUserID;
    	$promotionHandler 	 = new promotionHandler( $G_PGLOB->DBCA ) ;
    	$result_array 		 = $promotionHandler->saveUserSelectorInfo( $_REQUEST ) ;
    	echo json_encode($result_array);
    }
    
	
	/**
	 * 删除用户筛选器信息
	 *
	 */
	private function deleteSelector () {
		global $G_PGLOB;
		
    	$promotionHandler = new promotionHandler( $G_PGLOB->DBCA ) ;
    	$result_array 	  = $promotionHandler->deleteUserSelector( $_REQUEST ) ;
    	echo json_encode($result_array);
	}
	
	/**
	 * 查询用户信息
	 *
	 */
	private function getUserInfo(){
		global $G_PGLOB;
		
    	$promotionHandler = new promotionHandler( $G_PGLOB->DBCA ) ;
    	$result_array 	  = $promotionHandler->getUserInfo( $_REQUEST ) ;
    	echo json_encode($result_array);
	}
}